package com.problem.leetcode;

import java.util.HashSet;

/**
 * @author didi
 * @DESCRIPTION
 * @create 2019-04-28 18:26
 **/

public class Problem349 {
    public int[] intersection(int[] nums1, int[] nums2) {
        HashSet<Integer> hashSet = new HashSet<>();
        for (int index = 0; index < nums1.length; index++) {
            hashSet.add(nums1[index]);
        }

        HashSet<Integer> result = new HashSet<>();
        for (int index = 0; index < nums2.length; index++) {
            if (hashSet.contains(nums2[index])) {
                result.add(nums2[index]);
            }
        }

        int[] tmp   = new int[result.size()];
        int   count = 0;
        for (Integer ele : result) {
            tmp[count++] = ele;
        }

        return tmp;
    }
}
